/**
 * 
 */
package com.base.myproject.client.busi.b2c;

import java.util.List;

import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.store.Record;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.GridView;

/**
 * @author zgw
 *2009-7-15 下午03:17:57
 * javazgw@gmail.com
 */
public class BaseGridView extends GridView{

	protected String doRender(List<ColumnData> cs, List<ModelData> rows, int startRow, int colCount, boolean stripe) {
	    int last = colCount - 1;
	    String tstyle = "width:" + getTotalWidth() + "px;";

	    StringBuilder buf = new StringBuilder();
	    StringBuilder cb = new StringBuilder();

	    for (int j = 0; j < (rows.size()); j++) {
	      ModelData model = (ModelData) rows.get(j);
	      Record r = ds.hasRecord(model) ? ds.getRecord(model) : null;

	      int rowIndex = (j + startRow);
	      //Map<String, Widget> rowMap = new FastMap<Widget>();
	     // widgetMap.add(rowIndex, rowMap);
	      for(int k=0;k<2;k++)
	     for (int i = 0; i < colCount; i++) {
	        ColumnData c = cs.get(i);
	        c.css = c.css == null ? "" : c.css;
	        String rv = getRenderedValue(c, rowIndex, i, model, c.name);

	        String css = (i == 0 ? "x-grid-cell-first " : (i == last ? "x-grid3-cell-last " : " ")) + " "
	            + (c.css == null ? "" : c.css);
	        String attr = c.cellAttr != null ? c.cellAttr : "";
	        String cellAttr = c.cellAttr != null ? c.cellAttr : "";

	        if (isShowDirtyCells() && r != null && r.getChanges().containsKey(c.id)) {
	          css += " x-grid3-dirty-cell";
	        }

	        cb.append("<td class=\"x-grid3-col x-grid3-cell x-grid3-td-");
	        cb.append(c.id);
	        cb.append(" ");
	        cb.append(css);
	        cb.append("\" style=\"");
	        cb.append(c.style);
	        cb.append("\" tabIndex=0 ");
	        cb.append(cellAttr);
	        cb.append("><div class=\"x-grid3-cell-inner x-grid3-col-");
	        cb.append(c.id);
	        cb.append("\" ");
	        cb.append(attr);
	        cb.append(">");
	        cb.append(rv);
	        cb.append("</div></td>");
	      }
//	      for(int k=0;k<3;k++)
//	      {
//	    	  cb.append("<td>000</td>");
//	      }
	      String alt = "";
	      if (stripe && ((rowIndex + 1) % 2 == 0)) {
	        alt += " x-grid3-row-alt";
	      }

	      if (isShowDirtyCells() && r != null && r.isDirty()) {
	        alt += " x-grid3-dirty-row";
	      }

	      if (viewConfig != null) {
	        alt += " " + viewConfig.getRowStyle(model, rowIndex, ds);
	      }

	      buf.append("<div class=\"x-grid3-row ");
	      buf.append(alt);
	      buf.append("\" style=\"");
	      buf.append(tstyle);
	      buf.append("\"><table class=x-grid3-row-table border=0 cellspacing=0 cellpadding=0 style=\"");
	      buf.append(tstyle);
	      buf.append("\"><tbody><tr>");
	      buf.append(cb.toString());
	      buf.append("</tr>");
	      buf.append((enableRowBody
	          ? ("<tr class=x-grid3-row-body-tr style=\"\"><td colspan=" + colCount + " class=x-grid3-body-cell tabIndex=0><div class=x-grid3-row-body>${body}</div></td></tr>")
	          : ""));
	      buf.append("</tbody></table></div>");
	      cb = new StringBuilder();
	    }

	    return buf.toString();
	  }
}
